package com.clf.springBoot.modules.common.controller;

import com.clf.springBoot.modules.common.vo.ImageType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: chenglongfei
 * @date: 2022/7/6
 * @Description EnumController
 */
@RestController
@RequestMapping("/api")
public class EnumController {
    public static Map<String, Class> map = new HashMap(){{
        put("imageType", ImageType.class);
    }};
//	static {
//		map.put("imageType", ImageType.class);
//	}

    /**
     * 127.0.0.1/api/dictionary/imageType ---- get
     */
    @GetMapping(value = "/dictionary/{enumKey}")
    public List<Object> getEnum(@PathVariable String enumKey) {
        try {
            if (map.containsKey(enumKey)) {
                Class clazz = map.get(enumKey);
                Method method = clazz.getDeclaredMethod("values");
                Object[] temp = (Object[]) method.invoke(null);
                return Arrays.asList(temp);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

}
